import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'
// import HeaderRouter from './header-router'

// Workbench
import Workbench from '@/views/Workbench.vue'

// Dashboard
import ReportFrame from '@/views/report/ReportFrame.vue'
import DashboardListView from '@/views/report/DashboardListView.vue'
import ChartListView from '@/views/report/ChartListView.vue'

// Audience
import AudienceFrame from '@/views/audience/AudienceFrame.vue'

// Marketing
import MarketingFrame from '@/views/marketing/MarketingFrame.vue'

// Data
import DataFrame from '@/views/data/DataFrame.vue'
import DataSourceListView from '@/views/data/DataSourceListView.vue'
import DataSetListView from '@/views/data/DataSetListView.vue'

//Lab
import LabFrame from '@/views/lab/LabFrame.vue'

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    children: [
      {
        path: '',
        redirect: 'workbench'
      },
      {
        path: 'workbench',
        name: 'workbench',
        component: Workbench
      },
      {
        path: 'data',
        name: 'data-frame',
        component: DataFrame,
        children: [
          {
            path: '',
            redirect: 'datasource'
          },
          {
            path: 'datasource',
            name: 'datasource',
            component: DataSourceListView
          },
          {
            path: 'dataset',
            name: 'dataset',
            component: DataSetListView
          }
        ]
      },
      {
        path: 'report',
        name: 'report-frame',
        component: ReportFrame,
        children: [
          {
            path: '',
            redirect: 'dashboard'
          },
          {
            path: 'dashboard',
            name: 'dashboard',
            component: DashboardListView
          },
          {
            path: 'chart',
            name: 'chart',
            component: ChartListView
          }
        ]
      },
      {
        path: 'audience',
        component: AudienceFrame
      },
      {
        path: 'marketing',
        component: MarketingFrame
      },
      {
        path: 'lab',
        component: LabFrame
      }
    ]
  },
  {
    path: '',
    redirect: '/workbench'
  },
  { path: '/workbench', redirect: '/' },
  { path: '/user', redirect: '/' },
  { path: '/marketing', redirect: '/' }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
